# from langchain.prompts import FewShotPromptTemplate, PromptTemplate
from langchain_core.prompts import FewShotPromptTemplate,PromptTemplate

# examples
examples = [
    {"input":"北京下雨吗", "output":"北京"},
    {"input":"上海热吗", "output":"上海"}
]

# 定义如何格式化每个示例
example_prompt = PromptTemplate(
    input_variables=["input", "output"],
    template="输入：{input}\n输出：{output}",
)

# 构建FewShotPromptTemplate
few_shot_prompt = FewShotPromptTemplate(
    examples=examples,
    example_prompt=example_prompt,
    prefix="按提示的格式，输出内容",
    suffix="输入：{input}\n输出：",
    input_variables=["input"]  # 输入变量
)
# 生成最终的prompt
prompt = few_shot_prompt.format(input="上海天气如何")
print(prompt)